package com.kh.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import com.kh.pojo.AjaxJson;
import com.kh.utils.Tools;

@ControllerAdvice
@EnableWebMvc
public class MyExceptionHandler {

	@ExceptionHandler(Exception.class)
	@ResponseBody
	public AjaxJson ajaxException(HttpServletRequest request, Exception e) {
		e.printStackTrace();
		AjaxJson ajaxJson=new AjaxJson();
		ajaxJson.setCode(-1);
		ajaxJson.setMessage("此url有问题");
		ajaxJson.setUrl(Tools.getRequestPath(request));
		return ajaxJson;
	}

}